<?php

namespace app\index\controller\source;

use app\index\model\UM as UM;
use app\index\service\SourceService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\Request as Request;

/**
 * Source 控制器
 * Class Source
 * @package app\index\controller\source;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 */
class Source
{
    // 请求参数
    private Request $request;

    // service
    private SourceService $service;

    public function __construct(Request $request, SourceService $sourceService)
    {
        $this->request = $request;
        $this->service = $sourceService;
    }

    /**
     * 案如云-线索列表
     * @param UM|null $user
     * @return ApiResponse
     * @url /source/source/index
     */
    public function index(?UM $user): ApiResponse
    {
        $request = $this->request;

        return ApiResponse::success($this->service->index($user, $request->param()));
    }

    /**
     * 案如云-线索详情
     * @param UM|null $user
     * @return ApiResponse
     * @url /source/source/read
     */
    public function read(UM $user): ApiResponse
    {
        $request = $this->request;

        return ApiResponse::success($this->service->read($user, $request->param()));
    }

}
